package base.day14.dao;

import base.day14.domain.Teacher;

import java.awt.print.Printable;

public class TeacherDao {
    static Teacher[] teas=new Teacher[5];
    public boolean addTeacher(Teacher teacher) {
        int index=-1;
        for (int i = 0; i < teas.length; i++) {
            Teacher tea=teas[i];
            if (tea==null){
                index=i;
                break;
            }
        }
        if (index==-1){
            return false;
        }else{
            teas[index]=teacher;
            return true;
        }
    }

    public Teacher[] findAllTeacher() {
        return teas;
    }

    public void deleteTeacherById(String deid) {
        int index=getIndex(deid);
        teas[index]=null;
    }
    public int getIndex(String id){
        int index=-1;
        for (int i = 0; i < teas.length; i++) {
            Teacher tea=teas[i];
            if (tea!=null&&tea.getId().equals(id)){
                index=i;
                break;
            }
        }
        return index;
    }

    public void upDateTeacher(String upid, Teacher teacher) {
        int index=getIndex(upid);
        teas[index]=teacher;
    }
}
